package com.xindaoapp.happypet.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.RelativeLayout.LayoutParams;
import android.widget.TextView;

import com.xindaoapp.happypet.R;

public class HorizontalListViewAdapter extends BaseAdapter {
	private final Context context;
	private final int mScreenWidth;
	private final int pageTotal;

	public HorizontalListViewAdapter(Context con, int mScreenWidth, int pageTotal) {
		mInflater = LayoutInflater.from(con);
		this.context = con;
		this.mScreenWidth = mScreenWidth;
		this.pageTotal = pageTotal;
	}

	@Override
	public int getCount() {
		return Integer.MAX_VALUE;
	}

	private final LayoutInflater mInflater;

	@Override
	public Object getItem(int position) {
		return position;
	}

	private static class ViewHolder {
		private TextView time;
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(final int position, View convertView, ViewGroup parent) {
		ViewHolder vh;
		if (convertView == null) {
			vh = new ViewHolder();
			convertView = mInflater.inflate(R.layout.horizontallistview_item, null);
			vh.time = (TextView) convertView.findViewById(R.id.tv_time);
			convertView.setTag(vh);
		} else {
			vh = (ViewHolder) convertView.getTag();
		}
		vh.time.setText(position % pageTotal + 1 + "");

		LayoutParams lp = new LayoutParams(mScreenWidth / 7, 100);
		convertView.setLayoutParams(lp);
		return convertView;
	}
}
